using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Markup;
using Rhizome.Contract;
using Rhizome.Contract.Diag;
using Rhizome.Model.Validation;

namespace Rhizome.Model
{
	[ContentProperty("Value")]
	public abstract class PropertyAndValueCriterionBase<TProperty> : PropertyCriterionBase<TProperty>
	{
		private TProperty _value;
		private bool _isValuePresent;

		protected PropertyAndValueCriterionBase(string property, TProperty value) : base(property)
		{
			Value = value;
		}

		protected PropertyAndValueCriterionBase(string property) : base(property)
		{
		}

		protected PropertyAndValueCriterionBase()
		{
		}

		public TProperty Value
		{
			[DebuggerStepThrough]
			get { return _value; }
			[DebuggerStepThrough]
			set
			{
				_value = value;
				_isValuePresent = true;
			}
		}

		#region Overrides of PropertyCriterionBase<TProperty>

		public override IEnumerable<IValidationResult> GetValidationResults()
		{
			return
				_isValuePresent
					? base.GetValidationResults()
					: base.GetValidationResults().Concat(new[] {ValidationResult.ValueNotSet});
		}

		#endregion
	}
}